<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <textarea name = "" id="" cols="30" rows="10"> </textarea>
    <script>
        const str='      im a teacher        '
        const tx = document.querySelector('textarea')
        tx.addEventListener('keyup', function(e) {
            if(e.key==='Enter'){
                console.log(tx.value.trim())
                }
            })

    </script>
</body>
</html>